package tool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class GetVertex {
	
	public static int[][] getVertex(){
		File fileVertex = new File(Settings.vertexFilePath);
		int rows = getFileRows(fileVertex);
		int[][] vertex = new int[rows][2];
		try {
			FileReader fr = new FileReader(fileVertex);
			BufferedReader br = new BufferedReader(fr);
			for(int i = 0; i < rows; i++){
				try {
					String line = br.readLine();
					String[] arr = line.split(" ");
					vertex[i][0] = Integer.parseInt(arr[0]);
					vertex[i][1] = Integer.parseInt(arr[1]);
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return vertex;
	}
	
	public static int getFileRows(File file){
		int rows = 0;
		try {
			FileInputStream fis = new FileInputStream(file);
			Scanner sc = new Scanner(fis);
			while(sc.hasNextLine()){
				rows++;
				sc.nextLine();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rows;
	}
}
